<template>
    <div class="container-fluid" v-loading="loading">
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header"><h4>cookie设置</h4></div>
                    <div class="card-toolbar clearfix">
                        <div class="toolbar-btn-action" style="padding-bottom:25px;">
                            <a class="btn btn-primary m-r-5 btn-sm" href="javascript:void(0)" @click="handleEdit(item)" v-for="item in list"><i class="mdi mdi-plus"></i> {{ item.title }}</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <el-dialog title="编辑cookie" :visible.sync="dialogFormVisible" :close-on-click-modal="false">
            <el-form :model="form">

                <el-form-item label="" :label-width="formLabelWidth">
                    <h5>{{form.title}}</h5>
                </el-form-item>

                <el-form-item label="cookie值" :label-width="formLabelWidth">
                    <el-input
                            type="textarea"
                            placeholder="请输入cookie"
                            v-model="form.cookie"
                            :rows="4"
                            maxlength="2000"
                            show-word-limit
                            style="width:80%;"
                    >
                    </el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="submitSet">确 定</el-button>
            </div>
        </el-dialog>

    </div>
</template>

<script>
    export default {
        name: "WechatCookieComponent",
        data(){
            return {
                dialogFormVisible: false,
                formLabelWidth: '120px',
                loading:false,
                list:[],
                form: {
                    title:'',
                    cookie: '',
                },
                uniqueId:''
            }
        },
        methods:{
            search: function () {
                let self = this;
                let uri = 'wechat-cookie/post-list';
                self.loading = true;
                let postData = {};

                axios.post(uri,postData).then(function (result) {
                    console.log(result);
                    self.list = result.data;
                    self.loading = false;
                }).catch(function (error) {
                    self.loading = false;
                });
            },
            handleEdit(item) {
                let self = this;
                self.dialogFormVisible = true;
                self.form.title = item.title;
                self.form.cookie = item.cookie || '';
                self.uniqueId = item.uniqueId;
                console.log(item)
            },
            submitSet:function () {
                let self = this;
                var uri = "wechat-cookie/" + self.uniqueId;
                self.dialogFormVisible = false;
                axios.put(uri, self.form).then(function (result) {
                    self.search();
                });
            }
        },
        mounted() {
            this.search();
        }
    }
</script>

<style scoped>
    .m-r-5 {
        margin-bottom: 20px;
    }
</style>
